<%@page import="com.remist.model.ImageMapBean"%>
<%@page import="com.remist.service.ImagesService"%>
<%@page import="com.remist.common.Constant"%>
<%@ page language="java" contentType="text/html; charset=gb2312" %>      
<%@ page import="com.jspsmart.upload.SmartUpload"%>   
<%@ page import="com.remist.common.FileTool"%>   
<%@ page import="java.io.*"%>   
    <%
String user = "";
    /*
if ( request.getSession().getAttribute("userName") != null)
	user = (String)request.getSession().getAttribute("userName");
else 
	response.sendRedirect("index.action");
*/
String contextPath = request.getContextPath();
%> 
<%    
String tmpFile = this.getServletContext().getRealPath("/");
File file = new File(tmpFile  + "temp"); 
String uploadFolder = "";
String returnPic = "";
if (!file.exists()) {
  file.mkdirs();
}
    SmartUpload su = new SmartUpload();      
     
    su.initialize(config, request, response);
    su.setMaxFileSize(10000000);      
     
    su.setTotalMaxFileSize(20000000);      
    boolean sign = true;      
    try {      
        su.upload();
        com.jspsmart.upload.File smartFile = su.getFiles().getFile(0);
        String fileName = smartFile.getFileName();
        uploadFolder = su.getRequest().getParameter("uploadFolder");
        String root = tmpFile+"upload"+File.separator	+ uploadFolder+File.separator;
        File tmp = new File(root);
		if ( !tmp.exists())
			tmp.mkdirs();
     /*   root = FileTool.getFolderPath(root, 0,false);*/
		File diskFile = new File(root,fileName  );
		returnPic = diskFile.getAbsolutePath();
		int begin = returnPic.indexOf("upload");
		returnPic = returnPic.substring(begin, returnPic.length() );
		returnPic = returnPic.replace("\\", "/");
		String saveDir = root+  fileName;
		smartFile.saveAs( saveDir );
 
    } catch (Exception e) {     
        e.printStackTrace();     
        sign = false;     
    }     
    if(sign==true)     
    {  
    	 ImageMapBean image = new ImageMapBean();
    	 image.setImageUrl(returnPic);
    	 image.setTypeId(Constant.TYPE_PRODUCT);
    	 image.setDelFlag(Constant.RECORD_STATUS_NORMAL);
    	((ImagesService)Constant.getSpringCtx().getBean("imagesService")).addImage(image);
  	  	out.println("<script>parent.callback('upload file success|"+ returnPic +"|"+image.getId()+"')</script>");  
    }else     
    {   
    	out.println("<script>parent.callback('upload file error')</script>");  
    }      
    %>   